home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 10 / AACD 10.iso / AACD / Resources / Online / Term / Extras / Source / gtlayout-source.lha / LT_FindMenuCommand.c < prev    next >
C/C++ Source or Header  |  1996-08-22  |  3KB  |  125 lines

  1. /*
  2. **    GadTools layout toolkit
  3. **
  4. **    Copyright © 1993-1996 by Olaf `Olsen' Barthel
  5. **        Freely distributable.
  6. **
  7. **    :ts=4
  8. */
  9.  
  10. #ifndef _GTLAYOUT_GLOBAL_H
  11. #include "gtlayout_global.h"
  12. #endif
  13.  
  14. #ifdef DO_MENUS
  15.  
  16. /****** gtlayout.library/LT_FindMenuCommand ******************************************
  17. *
  18. *   NAME
  19. *    LT_FindMenuCommand -- Get the menu/submenu item associated
  20. *                          with a rawkey event (V11)
  21. *
  22. *   SYNOPSIS
  23. *    Item = LT_FindMenuCommand(Menu,Code,Qualifier,Gadget)
  24. *     D0                        A0  D0       D0      A1
  25. *
  26. *    struct MenuItem *LT_FindMenuCommand(struct Menu *,
  27. *
  28. *                         UWORD,ULONG,struct Gadget *);
  29. *
  30. *   FUNCTION
  31. *    With the IntuiMessage data copied from a type IDCMP_RAWKEY message
  32. *    tries to find the MenuItem the event referred to.
  33. *
  34. *   INPUTS
  35. *    Menu - Pointer to Menu structure as returned by LT_NewMenuTagList.
  36. *
  37. *    Code - Value copied from IntuiMessage->Code
  38. *
  39. *    Qualifier - Value copied from IntuiMessage->Qualifier
  40. *
  41. *    Gadget - Value copied from IntuiMessage->IAddress
  42. *
  43. *   RESULT
  44. *    Item - Pointer to the struct MenuItem * in question or NULL
  45. *        if none could be found
  46. *
  47. *   SEE ALSO
  48. *    gtlayout.library/LT_NewMenuTagList
  49. *
  50. ******************************************************************************
  51. *
  52. */
  53.  
  54. struct MenuItem * LIBENT
  55. LT_FindMenuCommand(REG(a0) struct Menu *Menu,REG(d0) UWORD MsgCode,REG(d1) UWORD MsgQualifier,REG(a1) struct Gadget *MsgGadget)
  56. {
  57.     if(!Menu)
  58.         return(NULL);
  59.  
  60.         // Only take care of downstrokes
  61.  
  62.     if(!(MsgCode & IECODE_UP_PREFIX))
  63.     {
  64.         RootMenu            *Root = (RootMenu *)((ULONG)Menu - offsetof(RootMenu,Menu));
  65.         ItemNode            *Item;
  66.         struct InputEvent     Event;
  67.         UBYTE                 ANSIKey[10];
  68.         ULONG                 Qualifier;
  69.  
  70.             // Fix up the MsgQualifier
  71.  
  72.         if(MsgQualifier & QUALIFIER_SHIFT)
  73.             MsgQualifier = (MsgQualifier & ~QUALIFIER_SHIFT) | IEQUALIFIER_LSHIFT;
  74.  
  75.         if(MsgQualifier & QUALIFIER_ALT)
  76.             MsgQualifier = (MsgQualifier & ~QUALIFIER_ALT) | IEQUALIFIER_LALT;
  77.  
  78.             // Convert the key
  79.  
  80.         ANSIKey[0] = 0;
  81.  
  82.         Event.ie_NextEvent        = NULL;
  83.         Event.ie_Class            = IECLASS_RAWKEY;
  84.         Event.ie_SubClass        = 0;
  85.         Event.ie_Code            = MsgCode;
  86.         Event.ie_Qualifier        = MsgQualifier;
  87.         Event.ie_EventAddress    = (APTR)MsgGadget;
  88.  
  89.         if(!MapRawKey(&Event,ANSIKey,9,NULL))
  90.             ANSIKey[0] = 0;
  91.  
  92.             // Run down the list...
  93.  
  94.         for(Item = (ItemNode *)Root->ItemList.mlh_Head ; Item->Node.mln_Succ ; Item = (ItemNode *)Item->Node.mln_Succ)
  95.         {
  96.                 // See if we can do with the char
  97.  
  98.             if(Item->Char)
  99.             {
  100.                 if(Item->Char == ANSIKey[0])
  101.                     return(&Item->Item);
  102.             }
  103.             else
  104.             {
  105.                     // So that didn't work, what about the raw data?
  106.  
  107.                 Qualifier = Item->Qualifier;
  108.  
  109.                 if(Qualifier & QUALIFIER_SHIFT)
  110.                     Qualifier = (Qualifier & ~QUALIFIER_SHIFT) | IEQUALIFIER_LSHIFT;
  111.  
  112.                 if(Qualifier & QUALIFIER_ALT)
  113.                     Qualifier = (Qualifier & ~QUALIFIER_ALT) | IEQUALIFIER_LALT;
  114.  
  115.                 if(Item->Code == MsgCode && (MsgQualifier & Qualifier) == Qualifier)
  116.                     return(&Item->Item);
  117.             }
  118.         }
  119.     }
  120.  
  121.     return(NULL);
  122. }
  123.  
  124. #endif    /* DO_MENUS */
  125.